package com.cdvtc.news.web.api;

import com.cdvtc.news.dao.NewsDao;
import com.cdvtc.news.entity.News;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags={"新闻接口"})
@RestController
@RequestMapping("api")
public class NewsApiController {

    @Autowired
    private NewsDao newsDao;

    @RequestMapping("newsByCid/{categoryId}")
    public List<News>  getNewsByCategoryId(@PathVariable Integer categoryId) {
        return newsDao.getNewsByCategory(categoryId);
    }

    @RequestMapping("newsByTid/{tagId}")
    public List<News> getNewsByTagId(@PathVariable Integer tagId) {
        return newsDao.getNewsByTag(tagId);
    }

    @RequestMapping("news/{newsId}")
    public News getNewsById(@PathVariable Integer newsId) {
        return newsDao.getNewsById(newsId);
    }
}
